package cn.lotusnut.rabbitmqboot.topic;

import org.springframework.amqp.core.AmqpTemplate;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * @Author JiangMing Zhou
 * @Date 2022/12/1 15:02
 * @Version 1.8
 */
@Component
public class TopicProvider {
    @Resource
    private AmqpTemplate amqpTemplate;


    /**
     * 发送消息（简单模式）
     *
     * @param message 要发送的消息
     */
    public void sendMessage(String message) {
        for (int i = 0; i < 10; i++) {
            String routeKey = null;
            switch (i % 3) {
                case 0:
                    routeKey = "cat.aa";
                    break;
                case 1:
                    routeKey = "cat.dog";
                    break;
                case 2:
                    routeKey = "aa.dog";
                    break;
            }
            amqpTemplate.convertAndSend("topic_exchange", routeKey, message + i);
        }

    }
}
